<template>
  <el-aside width="200px">
    <el-row class="tac">
      <el-col>
        <el-menu
          default-active="1"
          class="el-menu-vertical-demo"
          @open="handleOpen"
          @close="handleClose"
        >
          <el-menu-item index="1" @click="goPage('home')">
            <i class="el-icon-menu"></i>
            <span slot="title">后台中心</span>
          </el-menu-item>

          <el-submenu index="2">
            <template #title>
              <i class="el-icon-search"></i>
              <span slot="title">信息检索</span>
            </template>
            <el-menu-item-group>
              <el-menu-item index="2-1" @click="goPage('studenttable')">
                <i class="el-icon-d-arrow-right"></i>学生信息
              </el-menu-item>
              <el-menu-item index="2-2" @click="goPage('teachertable')">
                <i class="el-icon-d-arrow-right"></i>教师信息
              </el-menu-item>
              <el-menu-item index="2-3" @click="goPage('coursetable')">
                <i class="el-icon-d-arrow-right"></i>课程信息
              </el-menu-item>
            </el-menu-item-group>
          </el-submenu>

          <el-menu-item index="3" @click="goPage('courseupdate')">
            <template #title>
              <i class="el-icon-reading"></i>
              <span slot="title">课程管理</span>
            </template>
          </el-menu-item>

          <el-menu-item index="4" @click="goPage('studentupdate')">
            <template #title>
              <i class="el-icon-s-custom"></i>
              <span slot="title">学生管理</span>
            </template>
          </el-menu-item>

          <el-menu-item index="5" @click="goPage('teacherupdate')">
            <template #title>
            <i class="el-icon-user"></i>
            <span slot="title">教师管理</span>
          </template></el-menu-item>

          <el-menu-item v-if="role === '4'|| role === '5'" index="6" @click="goPage('cartlist')">
            <i class="el-icon-wallet"></i>
            <span slot="title">订单管理</span>
          </el-menu-item>

          <el-menu-item v-if="role === '5'" index="7" @click="goPage('authority')">
            <i class="el-icon-setting"></i>
            <span slot="title">权限管理</span>
          </el-menu-item>
        </el-menu>
      </el-col>
    </el-row>
  </el-aside>
</template>

<script>
  var $this = {};
  export default {
    data() {
      return {
        role:''
      };
    },
    beforeCreate() {
      $this = this;
    },
    methods: {
      handleOpen(key, keyPath) {
        console.log(key, keyPath);
      },
      handleClose(key, keyPath) {
        console.log(key, keyPath);
      },

      goPage(link) {
        if (link === "home") {
          $this.$router.push("/home").catch(error => error);
        } else if ((link === "teachertable")) {
          $this.$router.push("/teachertable").catch(error => error);
        } else if(link === "courseupdate"){
          $this.$router.push("/courseupdate").catch(error => error);
        } else if(link === "studenttable") {
          $this.$router.push("/studenttable").catch(error => error);
        }else if(link === "coursetable"){
          $this.$router.push("/coursetable").catch(error => error);
        }else if(link === "studentupdate"){
          $this.$router.push("/studentupdate").catch(error => error);
        } else if(link === "teacherupdate"){
          $this.$router.push("/teacherupdate").catch(error => error);
        }else if(link === "addteacher"){
          $this.$router.push("/addteacher").catch(error => error);
        }else if(link === "cartlist"){
          $this.$router.push("/cartlist").catch(error => error);
        } else if(link === "authority"){
          $this.$router.push("/authority").catch(error => error);
        }
      }
    },
    mounted() {
      this.role = sessionStorage.getItem("role");
    }
  };
</script>

<style scoped>
  .el-row{
    height: 100%;
  }

  .el-menu{
    border-right:none;

  }
  .el-aside{
    border-right: 1px solid #f5f1f1;
  }
</style>
